<template>
	<view id="birth">
		<form >
			<view class="uni-list">
				<view class="uni-list-cell">
					<view class="uni-list-cell-db">
						<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
							<view class="uni-input" name="birth">{{date}}</view>
						</picker>
					</view>
				</view>
			</view>
			<button type="primary" @click="editbirth">修改生日</button>
		</form>
	</view>
</template>
<script>
	import common from '../../common/common.js';
	function getDate(type) {
		const date = new Date();

		let year = date.getFullYear();
		let month = date.getMonth() + 1;
		let day = date.getDate();

		if (type === 'start') {
			year = year - 100;
		} else if (type === 'end') {
			year = year ;
		}
		month = month > 9 ? month : '0' + month;;
		day = day > 9 ? day : '0' + day;

		return `${year}-${month}-${day}`;
	}
	export default {
		data() {
			return {
				multiIndex: [0, 0, 0],
				date: "",
				startDate:getDate('start'),
				endDate:getDate('end'),
				time: '12:01'
			}
		},
		onLoad(e) {
			this.date = e.birthday
		},
		methods: {
			bindDateChange: function(e) {
				this.date = e.detail.value
			},
			bindTimeChange: function(e) {
				this.time = e.detail.value
			},
			editbirth(){
				console.log(this.date)
				var userinfo = this.getGlobalUser('globaluser')
				userinfo.birthday = this.date
				uni.setStorageSync("globaluser",userinfo)
				uni.navigateBack({
					delta:1
				})
			}

		}
	}
</script>

<style>
	@import url("./editbirth.css");
.uni-picker-tips {
	font-size: 12px;
	color: #666;
	margin-bottom: 15px;
	padding: 0 15px;
	/* text-align: right; */
}
</style>
